﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EnterpriseFund.Common;
using System.Data;

namespace EnterpriseFund.Controllers
{
      [OutputCache(Duration = 0, VaryByParam = "none")]  
    public class QueryKeyNsrRKQKController : AdminBaseController
    {
        //
        // GET: /QueryKeyNsrRKQK/
          [AuthorityActionFilter("m_QueryKeyNsrRKQK", Order = 1)]
          [LogPageActionFilter("重点税源企业入库情况表", Order = 2)]
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ShowView(string y,string m)
        {
            ViewData["showData"] = GetNewData(y, m);
            return View();
        }

        private List<string> szList
        {
            get{
                List<string> s = new List<string>();
                s.Add("02");
                s.Add("16");
                s.Add("06");
                s.Add("04");
                return s;
            }
        }

        public DataTable GetTableColoums()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("pqmc");
            dt.Columns.Add("xh", typeof(decimal));
            dt.Columns.Add("alltq", typeof(decimal));
            dt.Columns.Add("allsntq", typeof(decimal));
            dt.Columns.Add("alltqbl", typeof(decimal), "iif(allsntq=0,0, (alltq-allsntq)/allsntq*100)");
            dt.Columns.Add("allljs", typeof(decimal));
            dt.Columns.Add("allsnljs", typeof(decimal));
            dt.Columns.Add("allljsbl", typeof(decimal), "iif(allsnljs=0,0, (allljs-allsnljs)/allsnljs*100)");
            dt.Columns.Add("allsnsj", typeof(decimal));
            foreach (string sz in szList)
            {
                dt.Columns.Add(sz + "tq", typeof(decimal));
                dt.Columns.Add(sz + "sntq", typeof(decimal));
                dt.Columns.Add(sz + "tqbl", typeof(decimal), "iif([" + sz + "sntq]=0,0, ([" + sz + "tq]-[" + sz + "sntq])/[" + sz + "sntq]*100)");
                dt.Columns.Add(sz + "ljs", typeof(decimal));
                dt.Columns.Add(sz + "snljs", typeof(decimal));
                dt.Columns.Add(sz + "ljsbl", typeof(decimal), "iif([" + sz + "snljs]=0,0, ([" + sz + "ljs]-[" + sz + "snljs])/[" + sz + "snljs]*100)");
                dt.Columns.Add(sz + "snsj", typeof(decimal));
            }
            //dt.Columns.Add("16tq", typeof(decimal));
            //dt.Columns.Add("16sntq", typeof(decimal));
            //dt.Columns.Add("16tqbl", typeof(decimal), "(16tq-16sntq)/16sntq*100");
            //dt.Columns.Add("16ljs", typeof(decimal));
            //dt.Columns.Add("16snljs", typeof(decimal));
            //dt.Columns.Add("16ljsbl", typeof(decimal), "(16ljs-16snljs)/16snljs*100");
            //dt.Columns.Add("16snsj", typeof(decimal));
            //dt.Columns.Add("06tq", typeof(decimal));
            //dt.Columns.Add("06sntq", typeof(decimal));
            //dt.Columns.Add("06tqbl", typeof(decimal), "(06tq-06sntq)/06sntq*100");
            //dt.Columns.Add("06ljs", typeof(decimal));
            //dt.Columns.Add("06snljs", typeof(decimal));
            //dt.Columns.Add("06ljsbl", typeof(decimal), "(06ljs-06snljs)/06snljs*100");
            //dt.Columns.Add("06snsj", typeof(decimal));
            //dt.Columns.Add("04tq", typeof(decimal));
            //dt.Columns.Add("04sntq", typeof(decimal));
            //dt.Columns.Add("04tqbl", typeof(decimal), "(04tq-04sntq)/04sntq*100");
            //dt.Columns.Add("04ljs", typeof(decimal));
            //dt.Columns.Add("04snljs", typeof(decimal));
            //dt.Columns.Add("04ljsbl", typeof(decimal), "(04ljs-04snljs)/04snljs*100");
            //dt.Columns.Add("04snsj", typeof(decimal));
            return dt;
        }

        public DataTable GetNewData(string y,string m)
        {
            DataTable newdt = GetTableColoums();
            List<Model.QueryKeyNsrRKQK> showList = GetList();
            BLL.VSBZSXX VSBZSXXBLL = new BLL.VSBZSXX();
            DataTable dt = VSBZSXXBLL.GetKeyNsrRKQK(int.Parse(y), int.Parse(m)).Tables[0];
            DataTable allDt = VSBZSXXBLL.GetKeyNsrRKQKAll(int.Parse(y), int.Parse(m)).Tables[0];
            int i = 1;
            DataRow sumDr = newdt.NewRow();
            sumDr["pqmc"] = "合计";
            foreach (Model.QueryKeyNsrRKQK q in showList)
            {
                DataRow preDr = newdt.NewRow();
                preDr["pqmc"] = q.pq_name;
                preDr["xh"] = i;
                i++;
                if (q.sonList != null && q.sonList.Count > 0)
                {
                    foreach (Model.QueryKeyNsrRKQK qs in q.sonList)
                    {
                        DataRow Predrz = newdt.NewRow();
                        Predrz["pqmc"] = qs.pq_name;
                        Predrz["xh"] = i;
                        i++;
                        if (qs.sonList != null && qs.sonList.Count > 0)
                        {
                            foreach (Model.QueryKeyNsrRKQK qsz in qs.sonList)
                            {
                                DataRow sonPredr = newdt.NewRow();
                                sonPredr["pqmc"] = qsz.pq_name;
                                sonPredr["xh"] = i;
                                i++;
                                if (qsz.pq_dm != "")
                                {
                                    var query = (from nm in dt.AsEnumerable()
                                                 group nm by new { ke1 = nm.Field<decimal>("NSRDZDAH"), ke2 = nm.Field<decimal>("PQ_DM"), ke3 = nm.Field<string>("NSRMC") } into g
                                                 where g.Key.ke2 == decimal.Parse(qsz.pq_dm)
                                                 select new
                                                 {
                                                     NSRDZDAH = g.Key.ke1,
                                                     NSRMC=g.Key.ke3
                                                 });
                                    foreach (var qy in query)
                                    {
                                        DataRow sondr = newdt.NewRow();
                                        sondr["pqmc"] = qy.NSRMC;
                                        sondr["xh"] = i;
                                        i++;
                                        newdt.Rows.Add(GetNsrRow(sondr, dt, allDt, qy.NSRDZDAH));
                                        foreach (DataColumn dc in newdt.Columns)
                                        {
                                            if (dc.ColumnName != "pqmc" && dc.ColumnName != "xh")
                                            {
                                                if (sonPredr[dc.ColumnName].ToString() == "")
                                                {
                                                    sonPredr[dc.ColumnName] = 0;
                                                }
                                                if (sondr[dc.ColumnName].ToString() == "")
                                                {
                                                    sondr[dc.ColumnName] = 0;
                                                }
                                                sonPredr[dc.ColumnName] = decimal.Parse(sonPredr[dc.ColumnName].ToString()) + decimal.Parse(sondr[dc.ColumnName].ToString());
                                            }
                                        }
                                    }

                                }
                                newdt.Rows.Add(sonPredr);

                                foreach (DataColumn dc in newdt.Columns)
                                {
                                    if (dc.ColumnName != "pqmc" && dc.ColumnName != "xh")
                                    {
                                        if (Predrz[dc.ColumnName].ToString() == "")
                                        {
                                            Predrz[dc.ColumnName] = 0;
                                        }
                                        if (sonPredr[dc.ColumnName].ToString() == "")
                                        {
                                            sonPredr[dc.ColumnName] = 0;
                                        }
                                        Predrz[dc.ColumnName] = decimal.Parse(Predrz[dc.ColumnName].ToString()) + decimal.Parse(sonPredr[dc.ColumnName].ToString());
                                    }
                                }

                            }

                            newdt.Rows.Add(Predrz);
                        }
                        else
                        {
                            DataRow sonPredr = newdt.NewRow();
                            sonPredr["pqmc"] = qs.pq_name;
                            sonPredr["xh"] = i;
                            i++;
                            if (qs.pq_dm != "")
                            {
                                List<string> dmList = qs.pq_dm.Split(',').ToList();
                                foreach (string dm in dmList)
                                {
                                    var query = (from nm in dt.AsEnumerable()
                                                 group nm by new { ke1 = nm.Field<decimal>("NSRDZDAH"), ke2 = nm.Field<decimal>("PQ_DM"), ke3 = nm.Field<string>("NSRMC") } into g
                                                 where g.Key.ke2 == decimal.Parse(dm)
                                                 select new
                                                 {
                                                     NSRDZDAH = g.Key.ke1,
                                                     NSRMC = g.Key.ke3
                                                 });
                                    foreach (var qy in query)
                                    {
                                        DataRow sondr = newdt.NewRow();
                                        sondr["pqmc"] = qy.NSRMC;
                                        sondr["xh"] = i;
                                        i++;
                                        newdt.Rows.Add(GetNsrRow(sondr, dt, allDt, qy.NSRDZDAH));
                                        foreach (DataColumn dc in newdt.Columns)
                                        {
                                            if (dc.ColumnName != "pqmc" && dc.ColumnName != "xh")
                                            {
                                                if (sonPredr[dc.ColumnName].ToString() == "")
                                                {
                                                    sonPredr[dc.ColumnName] = 0;
                                                }
                                                if (sondr[dc.ColumnName].ToString() == "")
                                                {
                                                    sondr[dc.ColumnName] = 0;
                                                }
                                                sonPredr[dc.ColumnName] = decimal.Parse(sonPredr[dc.ColumnName].ToString()) + decimal.Parse(sondr[dc.ColumnName].ToString());
                                            }
                                        }
                                    }
                                }
                            }
                            newdt.Rows.Add(sonPredr);
                            foreach (DataColumn dc in newdt.Columns)
                            {
                                if (dc.ColumnName != "pqmc" && dc.ColumnName != "xh")
                                {
                                    if (Predrz[dc.ColumnName].ToString() == "")
                                    {
                                        Predrz[dc.ColumnName] = 0;
                                    }
                                    if (sonPredr[dc.ColumnName].ToString() == "")
                                    {
                                        sonPredr[dc.ColumnName] = 0;
                                    }
                                    Predrz[dc.ColumnName] = decimal.Parse(Predrz[dc.ColumnName].ToString()) + decimal.Parse(sonPredr[dc.ColumnName].ToString());
                                }
                            }
                        }
                
                        foreach (DataColumn dc in newdt.Columns)
                        {
                            if (dc.ColumnName != "pqmc" && dc.ColumnName != "xh")
                            {
                                if (preDr[dc.ColumnName].ToString() == "")
                                {
                                    preDr[dc.ColumnName] = 0;
                                }
                                if (Predrz[dc.ColumnName].ToString() == "")
                                {
                                    Predrz[dc.ColumnName] = 0;
                                }
                                preDr[dc.ColumnName] = decimal.Parse(preDr[dc.ColumnName].ToString()) + decimal.Parse(Predrz[dc.ColumnName].ToString());
                            }
                        }
                    }
                }
                else
                {
                    DataRow sonPredr = newdt.NewRow();
                    sonPredr["pqmc"] = q.pq_name;
                    sonPredr["xh"] = i;
                    i++;
                    if (q.pq_dm != "")
                    {
                        List<string> dmList = q.pq_dm.Split(',').ToList();
                        foreach (string dm in dmList)
                        {
                            var query = (from nm in dt.AsEnumerable()
                                         group nm by new { ke1 = nm.Field<decimal>("NSRDZDAH"), ke2 = nm.Field<decimal>("PQ_DM"), ke3 = nm.Field<string>("NSRMC") } into g
                                         where g.Key.ke2 == decimal.Parse(dm)
                                         select new
                                         {
                                             NSRDZDAH = g.Key.ke1,
                                             NSRMC = g.Key.ke3
                                         });
                            foreach (var qy in query)
                            {
                                DataRow sondr = newdt.NewRow();
                                sondr["pqmc"] = qy.NSRMC;
                                sondr["xh"] = i;
                                i++;
                                newdt.Rows.Add(GetNsrRow(sondr, dt, allDt, qy.NSRDZDAH));
                                foreach (DataColumn dc in newdt.Columns)
                                {
                                    if (dc.ColumnName != "pqmc" && dc.ColumnName != "xh")
                                    {
                                        if (sonPredr[dc.ColumnName].ToString() == "")
                                        {
                                            sonPredr[dc.ColumnName] = 0;
                                        }
                                        if (sondr[dc.ColumnName].ToString() == "")
                                        {
                                            sondr[dc.ColumnName] = 0;
                                        }
                                        sonPredr[dc.ColumnName] = decimal.Parse(sonPredr[dc.ColumnName].ToString()) + decimal.Parse(sondr[dc.ColumnName].ToString());
                                    }
                                }
                            }
                        }

                    }
                    newdt.Rows.Add(sonPredr);
                }

                newdt.Rows.Add(preDr);

                foreach (DataColumn dc in newdt.Columns)
                {
                    if (dc.ColumnName != "pqmc" && dc.ColumnName != "xh")
                    {
                        if (sumDr[dc.ColumnName].ToString() == "")
                        {
                            sumDr[dc.ColumnName] = 0;
                        }
                        if (preDr[dc.ColumnName].ToString() == "")
                        {
                            preDr[dc.ColumnName] = 0;
                        }
                        sumDr[dc.ColumnName] = decimal.Parse(sumDr[dc.ColumnName].ToString()) + decimal.Parse(preDr[dc.ColumnName].ToString());
                    }
                }
            }
            sumDr["xh"] = i;
            newdt.Rows.Add(sumDr);
            DataTable newdt2 = new DataTable();
            newdt2 = newdt.Select("", "xh").CopyToDataTable();
            return newdt2;
        }

        private DataRow GetNsrRow(DataRow sondr, DataTable dt, DataTable allDt, decimal NSRDZDAH)
        {
            foreach (string sz in szList)
            {
                var queryData = (from nm in dt.AsEnumerable() where nm.Field<decimal>("NSRDZDAH") == NSRDZDAH && nm.Field<string>("ZSXM_DM") == sz select nm);
                if (queryData.Count() > 0)
                {
                    sondr[sz + "tq"] = decimal.Round(decimal.Parse(queryData.CopyToDataTable().Rows[0]["tq"].ToString())/10000);
                    sondr[sz + "ljs"] = decimal.Round(decimal.Parse(queryData.CopyToDataTable().Rows[0]["ljs"].ToString())/10000);
                    sondr[sz + "sntq"] = decimal.Round(decimal.Parse(queryData.CopyToDataTable().Rows[0]["sntq"].ToString())/10000);
                    sondr[sz + "snljs"] = decimal.Round(decimal.Parse(queryData.CopyToDataTable().Rows[0]["snljs"].ToString())/10000);
                    sondr[sz + "snsj"] = decimal.Round(decimal.Parse(queryData.CopyToDataTable().Rows[0]["snsj"].ToString()) / 10000);
                }
                else
                {
                    sondr[sz + "tq"] = 0;
                    sondr[sz + "ljs"] = 0;
                    sondr[sz + "sntq"] = 0;
                    sondr[sz + "snljs"] = 0;
                    sondr[sz + "snsj"] = 0;
                }
            }

            string sz2 = "all";
            var queryDataAll = (from nm in allDt.AsEnumerable() where nm.Field<decimal>("NSRDZDAH") == NSRDZDAH select nm);
            if (queryDataAll.Count() > 0)
            {
                sondr[sz2 + "tq"] = decimal.Round(decimal.Parse(queryDataAll.CopyToDataTable().Rows[0]["Alltq"].ToString())/10000);
                sondr[sz2 + "ljs"] = decimal.Round(decimal.Parse(queryDataAll.CopyToDataTable().Rows[0]["Allljs"].ToString())/10000);
                sondr[sz2 + "sntq"] = decimal.Round(decimal.Parse(queryDataAll.CopyToDataTable().Rows[0]["Allsntq"].ToString())/10000);
                sondr[sz2 + "snljs"] = decimal.Round(decimal.Parse(queryDataAll.CopyToDataTable().Rows[0]["Allsnljs"].ToString())/10000);
                sondr[sz2 + "snsj"] = decimal.Round(decimal.Parse(queryDataAll.CopyToDataTable().Rows[0]["Allsnsj"].ToString()) / 10000);
            }
            else
            {
                sondr[sz2 + "tq"] = 0;
                sondr[sz2 + "ljs"] = 0;
                sondr[sz2 + "sntq"] = 0;
                sondr[sz2 + "snljs"] = 0;
                sondr[sz2 + "snsj"] = 0;
            }
            return sondr;
        }

        /// <summary>
        /// 报表菜单在次修改
        /// </summary>
        /// <returns></returns>
        private List<Model.QueryKeyNsrRKQK> GetList()
        {
            List<Model.QueryKeyNsrRKQK> list = new List<Model.QueryKeyNsrRKQK>();

            List<Model.QueryKeyNsrRKQK> list2 = new List<Model.QueryKeyNsrRKQK>();

            List<Model.QueryKeyNsrRKQK> list3 = new List<Model.QueryKeyNsrRKQK>();

            Model.QueryKeyNsrRKQK m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "1.中海油大榭产业园区";
            m.pq_dm = "233020900111";
            list3.Add(m);
            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "2.宁波万华产业园区";
            m.pq_dm = "233020900112";
            list3.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "3.三菱产业园区";
            m.pq_dm = "233020900113";
            list3.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "（一）三大产业园区";
            m.sonList = list3;
            list2.Add(m);
            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "（二）传统行业";
            m.pq_dm = "233020900121,233020900122,233020900123";//121,122,123
            list2.Add(m);
            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "（三）其他工业";
            m.pq_dm = "233020900130";
            list2.Add(m);
            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "一、工业";
            m.sonList = list2;
            list.Add(m);

            list2 = new List<Model.QueryKeyNsrRKQK>();
            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "1.交通运输业";
            m.pq_dm = "233020900210";
            list2.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "2.港口仓储业";
            m.pq_dm = "233020900220";
            list2.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "二、港口物流业";
            m.sonList = list2;
            list.Add(m);

            list2 = new List<Model.QueryKeyNsrRKQK>();
            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "1.金融保险业";
            m.pq_dm = "233020900310";
            list2.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "2.煤炭批发业";
            m.pq_dm = "233020900320";
            list2.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "3.其他批发零售业";
            m.pq_dm = "233020900330";
            list2.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "4.股权投资业";
            m.pq_dm = "233020900340";
            list2.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "5.建筑房地产业";
            m.pq_dm = "233020900350";
            list2.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "6.其他行业";
            m.pq_dm = "233020900360";
            list2.Add(m);

            m = new Model.QueryKeyNsrRKQK();
            m.pq_name = "三、其他商贸服务业";
            m.sonList = list2;
            list.Add(m);
            return list;
        }

        public System.Web.Mvc.FileResult ToExecl()
        {
            string y = Fetch.Post("hidy");
            string m = Fetch.Post("hidm");
            List<Model.XlsModel> xlsModelList = new List<Model.XlsModel>();
            int totalRowCount = 2;

            Model.XlsModel xlsModel = new Model.XlsModel();
            xlsModel.RowSpan = 2;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "片区";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;

            xlsModelList.Add(xlsModel);


            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = 7;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "税收收入";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);

            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = 7;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "营业税";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);

            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = 7;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "城建税";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);

            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = 7;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "个人所得税";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);

            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = 7;
            xlsModel.RowIndex = totalRowCount;
            xlsModel.Title = "企业所得税";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);
            totalRowCount++;

            for (int i = 0; i < 5; i++)
            {
                xlsModel = new Model.XlsModel();
                xlsModel.ColSpan = 1;
                xlsModel.RowIndex = totalRowCount;
                xlsModel.Title = "本期数";
                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xlsModelList.Add(xlsModel);

                xlsModel = new Model.XlsModel();
                xlsModel.ColSpan = 1;
                xlsModel.RowIndex = totalRowCount;
                xlsModel.Title = "上年同期";
                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xlsModelList.Add(xlsModel);

                xlsModel = new Model.XlsModel();
                xlsModel.ColSpan = 1;
                xlsModel.RowIndex = totalRowCount;
                xlsModel.Title = "同比%";
                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xlsModelList.Add(xlsModel);

                xlsModel = new Model.XlsModel();
                xlsModel.ColSpan = 1;
                xlsModel.RowIndex = totalRowCount;
                xlsModel.Title = "累计数";
                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xlsModelList.Add(xlsModel);

                xlsModel = new Model.XlsModel();
                xlsModel.ColSpan = 1;
                xlsModel.RowIndex = totalRowCount;
                xlsModel.Title = "上年累计数";
                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xlsModelList.Add(xlsModel);

                xlsModel = new Model.XlsModel();
                xlsModel.ColSpan = 1;
                xlsModel.RowIndex = totalRowCount;
                xlsModel.Title = "同比%";
                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xlsModelList.Add(xlsModel);

                xlsModel = new Model.XlsModel();
                xlsModel.ColSpan = 1;
                xlsModel.RowIndex = totalRowCount;
                xlsModel.Title = "上年实际";
                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
                xlsModelList.Add(xlsModel);
            }


            xlsModel = new Model.XlsModel();
            xlsModel.ColSpan = 36;
            xlsModel.RowIndex = 1;
            xlsModel.BottomLineStyle = 0;
            xlsModel.RightLineStyle = 0;
            xlsModel.LeftLineStyle = 0;
            xlsModel.TopLineStyle = 0;
            xlsModel.Title = "制表日期：" + DateTime.Now.ToString("yyyy年MM月dd日") + "                                      （金额单位:万元）";
            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Center;
            xlsModelList.Add(xlsModel);


            DataTable dt = GetNewData(y, m);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                totalRowCount++;
                foreach (System.Data.DataColumn dc in dt.Columns)
                {
                    if (dc.ColumnName != "xh")
                    {
                        decimal d = 0;
                        if (decimal.TryParse(dt.Rows[i][dc.ColumnName].ToString(), out d))
                        {
                            if (dc.ColumnName.Contains("bl"))
                            {

                                xlsModel = new Model.XlsModel();
                                xlsModel.RowIndex = totalRowCount;
                                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Right;
                                xlsModel.Title = decimal.Round(decimal.Parse(dt.Rows[i][dc.ColumnName].ToString())).ToString();
                                xlsModelList.Add(xlsModel);
                            }
                            else
                            {
                                xlsModel = new Model.XlsModel();
                                xlsModel.RowIndex = totalRowCount;
                                xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Right;
                                xlsModel.Title = dt.Rows[i][dc.ColumnName].ToString();
                                xlsModelList.Add(xlsModel);
                            }
                        }
                        else
                        {
                            xlsModel = new Model.XlsModel();
                            xlsModel.RowIndex = totalRowCount;
                            xlsModel.Title = dt.Rows[i][dc.ColumnName].ToString();
                            xlsModel.HAlign = Model.XlsModel.HorizontalAlign.Left;
                            xlsModelList.Add(xlsModel);
                        }
                    }
                }
            }

            List<Model.XlsModel_Column> xlsModelColumns = new List<Model.XlsModel_Column>();
            xlsModelColumns.Add(new Model.XlsModel_Column()
            {
                ColumnIndexStart = 0,
                ColumnIndexEnd = 30,
                Width = 10
            });

            List<Model.XlsModel_Row> xlsModelRows = new List<Model.XlsModel_Row>();
            ushort rowCount = (ushort)(totalRowCount);
            xlsModelRows.Add(new Model.XlsModel_Row()
            {
                RowIndexStart = 1,
                RowIndexEnd = 1,
                RowHeight = 23
            });

            xlsModelRows.Add(new Model.XlsModel_Row()
            {
                RowIndexStart = 2,
                RowIndexEnd = 7,
                RowHeight = 12

            });
            xlsModelRows.Add(new Model.XlsModel_Row()
            {
                RowIndexStart = 8,
                RowIndexEnd = rowCount,
                RowHeight = 15

            });

            Model.ExcelTitleFont excelTitleFont = new Model.ExcelTitleFont()
            {
                FontName = "宋体",
                FontSize = 18,
                Bold = true
            };

            byte[] b = Common.ExcelClass.ExportToExcelReturnByte("", "大榭开发区重点税源税收入库情况表 ", "大榭开发区重点税源税收入库情况表" , excelTitleFont, totalRowCount, xlsModelList, xlsModelColumns, xlsModelRows);

            string name = "大榭开发区重点税源税收入库情况表.xls";
            return File(b, "application/vnd.ms-excel", HttpUtility.UrlEncode(name));
        }

    }
}
